//
//  main.c
//  aes_search
//
//  32bit_Pseudo random number generator/32位伪随机数生成器
//
//  Created by MAC on 2017/11/22.
//  Copyright © 2017年 blackay. All rights reserved.
//

#include<stdio.h>

//A和M是互质的两个大质数，通过y = Ax mod M 生成随机数y，x,y初始为1
#define A 48271L
#define M 2147483647
//全局种子变量Seed
static unsigned long long Seed = 1;


double Random(void)
{
    Seed = (A*Seed)%M;
    return (double) Seed/M*100000000;
    //return Seed/M*100000000;
}

int Num_to_Array(long long target, int flag){
    int temp_array[8],i;
    int temp=0;
    for(i=7;i>=0;i--){
        temp_array[i] = target % 10;
        target /= 10;
    }
    temp = C_Out(temp_array,flag);
    return temp;
}

void tenTtwo(int target)
{
    int j=3;
    int num=0;
    int d[4];  //暂时分配4块空间

    //短除法 将余数放置于数组中
    do
    {
        d[j]=(target%2);//余数
        target=(target/2);
        j--;
        num++;
    }while(j!=-1);

    //d[num]=1;  //最后一个数为1
    //逆向输出数组中的数据拼接成二进制数
    for(j=num-1;j>=0;j--)
        printf("%d",d[j]);
    //printf("\n");
    //return num;
}

int C_Out(int target[], int flag){
    return target[flag];
}

int Choose_flag(int flag){
    return flag%8;
}

int main() {
    int i,flag,count = 0;
    printf("How many?\n");
    scanf("%d",&count);
    for(i=0;i<count*8+1;i++){
        flag = Num_to_Array((long long)Random(),1);
        if(i!=0){
            tenTtwo(flag);
        }
        if(i!=0&&i%8==0){
            printf("\n");
        }
        flag = Choose_flag(flag);
        //printf("%lld\n",(long long)Random());
    }
    printf("\n");
    return 0;
}
